﻿using MediatR;
using Traceability.Commont.Domains.AnimalsDomainFiles;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.Scalesetting
{
    public class ScaleDisplayHtmlHandler : IRequestHandler<ScaleDisplayHtmlCommond, PageDTO<Scale>>
    {

        private readonly IBateRepository<Scale> _scale;


        public ScaleDisplayHtmlHandler(IBateRepository<Scale> scale)
        {
            _scale = scale;
        }

        public async Task<PageDTO<Scale>> Handle(ScaleDisplayHtmlCommond request, CancellationToken cancellationToken)
        {
            var list = new PageDTO<Scale>() { pageCount = 0, totalCount = 0 };



            var query = _scale.GetAll().ToList();

            if (request.SacleName != null)
            {
                query = query.Where(x => x.ScaleName.Contains(request.SacleName)).ToList();
            }

            list.totalCount = query.Count();
            list.pageCount = (int)Math.Ceiling(query.Count() * 1.0 / request.pagesize);

            list.Lists = query.ToList();


            return list;

        }

        


    }
}
